/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        message_kernel.h
// Purpose:     
// Author:      syy
// Modified by: 
// Created:     2014/5/13 16:30
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////
#ifndef _MESSAGE_KERNEL_H_
#define _MESSAGE_KERNEL_H_

#include "qbmessage.h"
#include "core/common_types.h"
#include "core/comdefs.h"
#include "qbnet/include/network_service.h"
#include "../include/message_sync.h"
#include "../include/message_process.h"

// {E0D1CC64-29FD-4277-9D94-FEC6D6FCA1C3}
DEFINE_GUID(CLSID_MessageKernel, 
			0xe0d1cc64, 0x29fd, 0x4277, 0x9d, 0x94, 0xfe, 0xc6, 0xd6, 0xfc, 0xa1, 0xc3);

// {446601CF-0759-4022-A719-E01FE7998E4E}
DEFINE_GUID(IID_IMessageKernel, 
			0x446601cf, 0x759, 0x4022, 0xa7, 0x19, 0xe0, 0x1f, 0xe7, 0x99, 0x8e, 0x4e);

#ifdef _MSC_VER
extern "C" S_QBMESSGAE_EXPORT HRESULT __stdcall QtDllGetClassObject(REFCLSID rclsid,
                                                                    REFIID riid,
                                                                    LPVOID * ppv);
#else
STDAPI MessageKernel_CreateObject(REFCLSID rclsid,
                                  REFIID riid,
                                  LPVOID* ppv);
#endif

#ifdef __cplusplus
extern "C" {
#endif

    DECLARE_INTERFACE_(IMessageKernelObserver, IUnknown)
    {
        STDMETHOD_(void, OnRecvMsg) (char* pData, int nDataLen) PURE;
		STDMETHOD_(void, OnRecvNetStatus) (qb::NetStatus status, short retcode) PURE; // retcode为0表示成功
																					  // retcode小于0是自定义的错误码，定义在eNetErrorCode中
																					  // retcode大于0，是服务端的错误码返回，根据NetStatus不同阶段，有相对应的错误码
    };

	DECLARE_INTERFACE_(IMessageKernel, IUnknown)
	{
		STDMETHOD_(int32_t,Create) (THIS_ INetworkService* ins, IMessageSync* sync, IMessageProcess* process) PURE;
		STDMETHOD_(int32_t,Destory) (THIS_) PURE;
        STDMETHOD_(int32_t,RegisterMessageKernelObserver) (THIS_ IMessageKernelObserver* observer) PURE;
        STDMETHOD_(int32_t,DeRegisterMessageKernelObserver) (THIS_ IMessageKernelObserver* observer) PURE;
		STDMETHOD_(int32_t,NotifyNetStatus) (THIS_ qb::NetStatus status, short retcode) PURE;
		STDMETHOD_(int32_t,CreateConnect) (THIS_) PURE; // return connect_id
		STDMETHOD_(int32_t,Connect) (THIS_ int32_t connect_id, const char* ip, uint32_t port) PURE;
		STDMETHOD_(int32_t,Send) (THIS_ int32_t connect_id, const char* buff, uint32_t bytes) PURE;
		STDMETHOD_(int32_t,RegisterNetwork) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,DeRegisterNetwork) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,CloseConnect) (THIS_ int32_t connect_id) PURE;
	};

#ifdef __cplusplus
}
#endif
#endif // _MESSAGE_KERNEL_H_
